package de.akad.imp03.server;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.util.DAOBase;

import de.akad.imp03.shared.PersonObjectify;


public class PersonDao extends DAOBase {
	
	static {
		ObjectifyService.register(PersonObjectify.class);
	}
	
	// load, save, find
	public PersonObjectify load(Long id) {
		PersonObjectify p = ofy().get(PersonObjectify.class, id);
		return p;
	}
	
	public Long save(PersonObjectify p) {
		Key<PersonObjectify> key = ofy().put(p);
		return key.getId();
	}
	
	public Boolean delete(PersonObjectify p) {
		ofy().delete(p);
		return true; // just a dummy
	}
	
	public List<PersonObjectify> findAll() {
		Iterator<PersonObjectify> iter = ofy().query(PersonObjectify.class).iterator();
		ArrayList<PersonObjectify> result = new ArrayList<PersonObjectify>();
		while (iter.hasNext()) {
			result.add(iter.next());
		}
		return result;
	}
}
